package unrn.isiii.model;

import java.io.Serializable;

import javax.jdo.annotations.Embedded;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "punto")
@XmlRootElement
public class Punto implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4474851629392283304L;

	@Id
	@GeneratedValue
	private Long id;

	
	@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST,
			CascadeType.MERGE })
	@NotNull(message = "El campo recorrido no puede quedar vacio")
	@JoinColumn(name = "recorrido_id", nullable = false, referencedColumnName = "id")
	private Recorrido recorrido;

	@Embedded
	private Coordenada coordenada = new Coordenada();

	

	public Punto() {
		super();
		// TODO Auto-generated constructor stub
	}

	

	public Punto(Coordenada coordenada) {
		super();
		this.coordenada = coordenada;
	}



	@XmlElement
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	
	@XmlElement
	public Coordenada getCoordenada() {
		return coordenada;
	}

	public void setCoordenada(Coordenada coordenada) {
		this.coordenada = coordenada;
	}

	
	
	
	@XmlTransient
	public Recorrido getRecorrido() {
		return recorrido;
	}



	public void setRecorrido(Recorrido recorrido) {
		this.recorrido = recorrido;
	}



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Punto other = (Punto) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public boolean marcada() {
		if (this.getCoordenada() != null) {
			return true;
		}
		return false;
	}
}
